package dpss.client;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import dpss.commons.Repo;

/**
 * 
 * @author Shewetaank Indora
 *
 */
public class ServerDetails {
	
	private static final String FILE_PROPERTIES = "project.properties";
	/**
	 * Get the user's server's IP Address
	 * 
	 * @throws ParserConfigurationException
	 * 
	 */
	public String getRepo(String ipAddress) throws ParserConfigurationException {
		Properties prop = new Properties();
		InputStream input = null;
		String serverAddress = null;
		try {
			input = new FileInputStream(FILE_PROPERTIES);
			prop.load(input);

			String repo_path = prop.getProperty("repo.path");

			Repo repo = new Repo(repo_path);
			Map<String, String> testMap = repo.getServerInfo(ipAddress);

			serverAddress = testMap.get("id");

		} catch (IOException ex) {
			ex.printStackTrace();
		} catch (SAXException ex) {
			ex.printStackTrace();
		} finally {
		}
		if (input != null) {
			try {
				input.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return serverAddress;
	}

}
